<template>
  <div class="mycomment" v-if="commendedGoods">
    <my-header title="我的评论">
      <template #right>
        <slot name="right"> &nbsp; </slot>
      </template>
    </my-header>

    <div class="wrap">
      <div class="avoidDuplicate">
        <div class="content" v-for="(l, i) in this.commendedGoods" :key="i">
          <van-card
            :title="l.name"
            :thumb="l.img[0]"
            :desc="'「' + l.ipRightList[0].ipRightName + '」'"
            @click="gotoDetail(l.itemsId)"
          >
            <template #tags>
              <van-tag plain type="danger">{{ l.itemTags[0].name }}</van-tag>
            </template>
          </van-card>
        </div>

        <div class="avoidDuplicate">
          <div
            class="comment"
            v-for="(item, index) in commentList"
            :key="index"
          >
            <p class="title">我的评论</p>
            <p class="textcontent">：{{ item.content }}</p>
          </div>
        </div>
      </div>
    </div>

    <!-- footer -->
    <div class="footer">
      <!-- <div class="footer" v-if="isHeight"> -->
      <span class="">快去为喜欢的商品评论吧~</span>
      <img src="../../assets/images/ranran.png" alt="" />
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // 评论过的商品列表
      commendedGoods: [],
      commentList: [],
      // 是否显示底部嘉然
      isHeight: true,
    };
  },
  methods: {
    //   跳转到详情页
    gotoDetail(itemsId) {
      this.$router.push({ name: "detail", query: { itemsId: itemsId } });
    },
    async getOLComment() {
      let res = await this.$ajax.getOLCommentData({
        phone: this.userInfo.phone,
      });
      // console.log(res);
      this.commentList = res;
      console.log(this.commentList);
      // 获取商品详情信息
      res.forEach((item) => {
        this.$ajax
          .getGoodDetailData({
            itemsId: item.gid,
          })
          .then((result) => {
            // console.log(result);
            this.commendedGoods.push(result.data);
          });
      });
      if (this.commendedGoods.length > 2) {
        this.isHeight = false;
      }
      console.log(this.commendedGoods);
      console.log(this.commendedGoods.length);
    },
  },
  mounted() {
    this.getOLComment();
  },
};
</script>

<style lang="scss" scoped>
.mycomment {
  width: 100%;
  height: 100vh;
  .wrap {
    .content {
      border-top: 5px solid rgba($color: #ff99b1, $alpha: 0.3);
      .pswrap {
        display: flex;
        justify-content: space-between;
        .pxc {
          margin-left: 115px;
          font-size: 14px;
          color: #ff80aa;
          b {
            font-size: 12px;
          }
        }
      }
    }
    .comment {
      padding: 15px;
      width: 100%;
      .title {
        font-size: 18px;
        font-weight: bold;
      }
      .textcontent {
        margin-top: 6px;
        padding-left: 10px;
        background: #eee;
        border: 1px solid aliceblue;
        box-shadow: 2px 2px 0 0 aliceblue;
        border-radius: 15px;
        width: 100%;
        height: 30px;
        line-height: 30px;

        // height: 200px;
      }
    }
  }
  .footer {
    position: fixed;
    bottom: 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    span {
      color: #ff80aa;
      text-shadow: 2px 0 1px #ccc;
      font-size: 20px;
    }
    img {
      width: 50%;
    }
  }
}
</style>